package com.eras.shoes.ui

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.recyclerview.widget.RecyclerView
import com.eras.shoes.R
import com.eras.shoes.utils.ToastUtils
import com.google.zxing.integration.android.IntentIntegrator
import com.google.zxing.integration.android.IntentResult

class AssemblyActivity : ComponentActivity(), View.OnClickListener {

    private val tvAssemblyBack: TextView by lazy { findViewById<TextView>(R.id.tv_assembly_back) }
    private val tvAssemblyRefresh: TextView by lazy { findViewById<TextView>(R.id.tv_assembly_refresh) }
    private val tvShoesRefresh: RecyclerView by lazy { findViewById<RecyclerView>(R.id.rv_assembly_bt) }
    private val btnAssemblyPutinComparisonShoes: Button by lazy { findViewById<Button>(R.id.btn_assembly_putin_comparison_shoes) }
    private val tvAssemblyPutinComparisonResultShoes: TextView by lazy { findViewById<TextView>(R.id.tv_assembly_putin_comparison_result_shoes) }
    private val btnScanCodeTwoShoes: Button by lazy { findViewById<Button>(R.id.btn_scan_code_two_shoes) }
    private val tvSerialNumberTwoShoes: TextView by lazy { findViewById<TextView>(R.id.tv_serial_number_two_shoes) }
    private val tvSerialNumberComparisonResultTwoShoes: TextView by lazy { findViewById<TextView>(R.id.tv_serial_number_comparison_result_two_shoes) }
    private val btnPutinComparisonTwoShoes: Button by lazy { findViewById<Button>(R.id.btn_putin_comparison_two_shoes) }
    private val tvPutinComparisonResultTwoShoes: TextView by lazy { findViewById<TextView>(R.id.tv_putin_comparison_result_two_shoes) }
    private val btnScanCodeShoes: Button by lazy { findViewById<Button>(R.id.btn_scan_code_shoes) }
    private val tvSerialNumberShoes: TextView by lazy { findViewById<TextView>(R.id.tv_serial_number_shoes) }
    private val tvSerialNumberComparisonResultShoes: TextView by lazy { findViewById<TextView>(R.id.tv_serial_number_comparison_result_shoes) }
    private val btnPutinComparisonShoes: Button by lazy { findViewById<Button>(R.id.btn_putin_comparison_shoes) }
    private val tvPutinComparisonResultShoes: TextView by lazy { findViewById<TextView>(R.id.tv_putin_comparison_result_shoes) }
    private val btnSaveShoes: Button by lazy { findViewById<Button>(R.id.btn_save_shoes) }
    private val tvSaveShoesResult: TextView by lazy { findViewById<TextView>(R.id.tv_save_shoes_result) }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.layout_assembly)
        tvAssemblyBack.setOnClickListener(this)
        btnAssemblyPutinComparisonShoes.setOnClickListener(this)
        btnScanCodeTwoShoes.setOnClickListener(this)
        btnPutinComparisonTwoShoes.setOnClickListener(this)
        btnScanCodeShoes.setOnClickListener(this)
        btnPutinComparisonShoes.setOnClickListener(this)
        btnSaveShoes.setOnClickListener(this)

    }

    override fun onClick(p0: View?) {
        when(p0?.id) {
            R.id.tv_assembly_back -> {
                finish()
            }
            R.id.btn_assembly_putin_comparison_shoes -> {
                finish()
            }
            R.id.btn_scan_code_two_shoes -> {
                // 扫描二维码
                IntentIntegrator(this).initiateScan()
            }
            R.id.btn_putin_comparison_two_shoes -> {
                finish()
            }
            R.id.btn_scan_code_shoes -> {
                // 扫描二维码
                IntentIntegrator(this).initiateScan()
            }
            R.id.btn_putin_comparison_shoes -> {
                finish()
            }
            R.id.btn_save_shoes -> {
                finish()
            }

        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        val result: IntentResult? = IntentIntegrator.parseActivityResult(requestCode, resultCode, data)
        if (result != null) {
            if (result.contents != null) {
                // 扫描结果，result.contents是二维码内容
                val qrCodeContent = result.contents
                ToastUtils().show(this, "qrCodeContent="+qrCodeContent)

                // 这里可以添加HTTP请求获取数据的代码
                // 例如使用kotlinx.coroutines或者其他网络库发起请求
            } else {
                // 扫描失败
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data)
        }
    }

}